#include "config.h"
#include "utils.h"


bool debug = false;

// const String env = "redmi";
String env = "pro";
String SERVER_IP = " ";
String PORT = "8088";

String  DEV_PORT_HTTP = "8082";

// const String SERVER_IP = "47.115.200.180";
// const String PORT = "8087";

String WEB_SERVER_URL = "http://" + SERVER_IP + ":" + PORT;
String WS_SERVER_URL;

String ssid_dev="MERCURY_ZCC";
String password_dev="zcc123456";

// String ssid_dev="CMCC-76D9";
// String password_dev="x13871144685";

// String ssid_dev="CMCC-2403";
// String password_dev="37547UF@";

static  String ssid;
static   String password;
 
String server_ip_pro="www.smartlinked.cn";
//String server_ip_dev = "192.168.10.7";
String server_ip_dev = "192.168.0.105";

  String getSsid(){
    return ssid;
  }


  String getPassword(){
    return password;
  }

long getDefualtWakeupInterval()
{
    if (env.equals("dev"))
    {
        return 60;
    }
    else
    {
        return 60 * 5;
    }
}

String getEspIdAesBase64()
{
    String str = getEspId();
    char chars[str.length()];
    strcpy(chars, str.c_str());
    Serial.println("chars:");
    Serial.println(sizeof(chars));
    Serial.println(chars);
    return encryptBase64(chars);
}

void config()
{

     String localenv =  getPreferenceString("env");
     localenv = "pro";//配置环境

    if(!localenv.isEmpty()){
        env = localenv;
    }
    if(env.equals("dev")){


        setSsid(ssid_dev);
        //ssid = ssid_dev;
        //password=password_dev;
        setPassword(password_dev);

    }else{
     

        setSsid(getPreferenceString("ssid_pro"));
        setPassword(getPreferenceString("password_pro"));
     

       // ssid="MERCURY_ZCC";//测试
       // password = "zcc123456";
    }
    if (env.equals("dev"))
    {
        SERVER_IP = server_ip_dev;
        PORT = "8082";
        WEB_SERVER_URL = "http://" + SERVER_IP + ":" + PORT;
        WS_SERVER_URL = SERVER_IP;
    }
    else if (env.equals("pro"))
    {
        SERVER_IP = server_ip_pro;
        PORT = "8088";

        WEB_SERVER_URL = "http://" + SERVER_IP+":"+PORT;

       // WEB_SERVER_URL = "https://" + SERVER_IP ;
        WS_SERVER_URL = SERVER_IP;
    }
    else if (env.equals("redmi"))
    {
        // 192.168.48.221
        SERVER_IP = "192.168.48.221";
        PORT = "8081";
        WEB_SERVER_URL = "http://" + SERVER_IP + ":" + PORT;
        WS_SERVER_URL = SERVER_IP;
    }
}

  String getServerIp(){
    return SERVER_IP;
  }

bool isDev()
{
    return env.equals("dev");
}

  String getEnv(){
    return env;
  }

void setEnv(String envVal)
{
    env = envVal;
    putPreferenceString("env",envVal);//保存当前环境
    ESP.restart();
}

  void changeEnvMode(){
    if(env.equals("dev")){
        setEnv("pro");
    }else{
         setEnv("dev");
    }
  }

   void setSsid(String ssidVal){
        ssid = ssidVal;
   }
  void setPassword(String pwdVal){
      password = pwdVal;
  }